home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
hobby
/
gim_308.zip
/
GIM11E.DOC
< prev
next >
Wrap
Text File
|
1993-04-17
|
10KB
|
276 lines
CHAPTER 11 LISTS OF SIMILAR PERSONS, FAMILIES AND NOTES
OR
SEARCHING YOUR FOLDER FOR SPECIFIC INFORMATION
PART E: CONJUNCTIONS USED IN WHERE COMMANDS
In this section we assume that you know what a WHERE command
is, how it's used, and what it's used for. We also assume
that you know what operators and operands in WHERE commands
are, and how they are used. If you haven't done so already,
review the first section in this chapter, which is entitled
"An Introduction with Basic Examples", and skim the sections
entitled "Operators Used in WHERE Commands" and "Operands
Used in WHERE Commands".
DEFINITION...
DEFINITION: A CONJUNCTION
After reading those sections, you know how to make sense of
the following where commands:
WHERE birth date is after 1950
WHERE birth date is before 1970
But so far, we've kept quiet about how to search for dates
that are BETWEEN 1950 and 1970. That is done by combining
these two expressions into a single WHERE command by using
the word AND, as follows:
WHERE birth date is after 1950 AND birth date is before 1970
The word "AND" is a conjunction. GIM LISTS provides three
conjunctions: AND, OR, and NOT. This section explains how
to use these conjunctions in WHERE commands.
ATOMS...
DEFINITION: AN ATOM IN A WHERE COMMAND
All of the following are examples of atoms:
any place contains "Denmark"
full is "Abe Lincoln"
birth date is before 1964
general source note is missing
children gt 5
children le 7
If you've read all of the GIM LISTS sections of this manual
up to this point, you've seen dozens of atoms.
An atom is the smallest piece of a WHERE command that still
makes sense on its own. It consists of a left-hand operand,
an operator, and most of the time, a right-hand operand.
COMBINING...
COMBINING ATOMS TOGETHER
Atoms can be combined in all sorts of ways, as you will see.
For example, we could combine the first two atoms with an OR,
like this:
WHERE any place contains "Denmark" OR full is "Abe Lincoln"
Or we could combine the last two atoms with an AND, like this:
WHERE children GT 5 AND children LE 7
In fact, we can combine any number of atoms -- whatever they
are -- with ANDs and ORs and NOTs.
ABBREVIATIONS...
If you've read the previous several sections of this manual,
you know what an atom is. For the rest of this section, we
want to ignore the atoms and focus on the conjunctions.
To help with this, we're going to represent atoms with double
lower case letters -- like aa, bb, cc, and so on. When you
see an abbreviation like "aa", you should realize that "aa"
means "any atom that you want to put here". This will help
us to ignore the atoms in order to focus on the conjunctions.
In other words, we won't talk about these WHERE commands:
WHERE any place contains "Denmark" OR full is "Abe Lincoln"
WHERE children GT 5 AND children LE 7
... instead, we'll just refer to these:
WHERE aa OR bb
WHERE cc AND dd
That way we can talk about ANDs, ORs, and NOTs, without the
values of the atoms themselves distracting us from the
discussion of conjunctions.
PUTTING SOME OF THE PIECES TOGETHER...
You can join as many atoms together as you want, just as long
as there is an AND or an OR between each of them. For
example, any sequence like the following is perfectly legal:
WHERE aa AND bb OR cc
WHERE aa OR bb AND cc AND dd
WHERE aa AND bb AND cc AND dd OR ee AND ff AND gg
PRECEDENCE PROBLEM...
A PRECEDENCE PREDICAMENT
Now, this brings up an interesting predicament. Suppose for
a moment that "aa" is "blue eyes", "bb" is "blonde hair", and
"cc" is "female".
If I'm searching for "aa AND bb", then I'm searching for
someone with blue eyes AND blonde hair, and anyone I pick has
to have both in order to be selected.
On the other hand, if I'm searching for "aa OR bb", then I'm
searching for someone with EITHER blue eyes OR blonde hair;
it doesn't matter which -- I'll take someone with either one
or the other.
But what do I mean if I say "aa AND bb OR cc"? This could be
interpreted in either of two ways.
On the one hand, it could mean that I'm looking for EITHER
someone with blonde hair and blue eyes OR someone who's
female. That's one way to look at it, and it means that I'll
take any female, and I'll also take any blue-eyed, blonde-
haired male.
On the other hand, it could mean that I'm looking for someone
with blue eyes, and who also EITHER has blonde hair OR is
female. This is another way to look at it, and it means that
I'll take any blue-eyed, blonde-haired male, or any blue-eyed
female.
This confusion arises from a problem that is solved by
defining what's called "precedence". In other words, there
are "rules of precedence" that govern how GIM LISTS should
resolve ambiguous situations like this one.
PRECEDENCE SOLUTION...
THE PRECEDENCE PREDICAMENT SOLVED
The simplest of these "rules of precedence" is this: all
other things being equal, AND takes precedence over OR.
(If you are a programmer, this rule comes as no surprise.)
As a result, WHERE aa AND bb OR cc, from our example above,
should be thought of as:
WHERE aa AND bb OR cc
... rather than:
WHERE aa AND bb OR cc
PARENTHESIS...
PARENTHESIS PRECEDENCE
Now, if that's not what we mean, we can override the rules of
precedence by using parentheses. We can surround two or more
atoms and their conjunctions with parentheses. GIM LISTS
will evaluate everything inside parentheses before evaluating
anything outside of them. (Again, to a programmer, this rule
comes as no surprise.)
Therefore, if we really mean to say:
WHERE aa AND bb OR cc
... we can say this:
WHERE aa AND (bb OR cc)
AN EXAMPLE OF PARENTHESES
As another example, consider the following:
WHERE aa AND bb OR cc AND dd AND ee OR ff AND gg
Because all of the ANDs are grouped together first, GIM LISTS
looks at this WHERE command and interprets it like this:
WHERE aa AND bb
OR
cc AND dd AND ee
OR
ff AND gg
But you can change this with parentheses. For example, by
adding parentheses to our example, like this:
WHERE aa AND ((bb OR cc) AND dd) AND (ee OR ff) AND gg
... then we instruct GIM LISTS to interpret this as follows:
WHERE aa
AND
bb OR cc AND dd
AND
ee OR ff
AND
gg
Study this for a while, and you'll see what I mean. The use
of parentheses can get awfully intricate awfully fast, so
it's usually best to keep your WHERE commands as simple as
possible, just for your own sake. But bear in mind that GIM
LISTS can keep up with as many sets of parentheses as you can
dish out, which can be useful and reassuring in those cases
where you need your WHERE commands to be intricate.
NOT...
THE NOT MODIFIER
Any place where you can put an AND or an OR, you can put an
AND NOT or an OR NOT. So for example, you can say:
WHERE aa AND NOT bb
or
WHERE aa AND bb OR NOT cc
or
WHERE aa AND NOT (bb AND cc)
Doing so means what you think it means. If "aa" is "blue
eyes" and "bb" is "blonde hair", then "aa AND NOT bb" means
"anybody who has blue eyes but who also DOESN'T have blonde
hair." (Hint: if you find yourself trying to use the word
"BUT" in a where clause, use "AND NOT" instead.)
NOT may also be used by itself, without AND and OR, but this
usage is somewhat rare. For example, you can say:
WHERE NOT aa
... as for example:
WHERE NOT surname contains "Smith"
... but this simply means:
WHERE surname doesn't contain "Smith"
Therefore, although NOT may be used by itself, there are
almost always other ways to say the same thing.